<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>教师管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

<!--    <link rel="stylesheet" href="layui/css/layui.css" >-->
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <style>
        /* 移动端 */
        @media screen and (max-width: 768px) {
            .layui-layout-admin .layui-layout-left,
            .layui-layout-admin .layui-body,
            .layui-layout-admin .layui-footer{left: 0;}
            .layui-layout-admin .layui-side{left: -300px;}
        }
    </style>
</head>
<body>
<div class="layui-body"style="margin-left: -200px;">

    <!-- 搜索条件 -->
    <fieldset class="layui-elem-field">
        <legend>根据员工号和姓名查询员工信息：</legend>
        <div class="layui-field-box">
            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input type="text" id="search_username" placeholder="请输入姓名" class="layui-input">
                </div>

                <label class="layui-form-label">毕业大学</label>
                <div class="layui-input-inline">
                    <input type="text" id="search_collage" placeholder="请输入大学名称" class="layui-input">
                </div>

                <button class="layui-btn layui-btn-radius layui-btn-warm" id="iReset">重置</button>
                <button class="layui-btn layui-btn-radius layui-btn-normal" id="searchVal">搜索</button>
            </div>


        </div>
    </fieldset>


    <table class="layui-hide" id="test" lay-filter="test"></table>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="insertData">新增老师记录</button>
        </div>
    </script>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script type="text/html" id="insert_form">
        <div class="layui-field-box">

                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_username" class="layui-input" placeholder="请输入姓名">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_sex" class="layui-input" placeholder="请输入性别（1女，2男）">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">生日</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_birthday" class="layui-input" placeholder="请输入生日">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">成绩</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_grade" class="layui-input" placeholder="请输入成绩">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">等级</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_rank" class="layui-input" placeholder="请输入等级">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">工作日志</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_jobDate" class="layui-input" placeholder="请输入工作日志">
                </div>
            </div>


            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">大学</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_collage" class="layui-input" placeholder="请输入大学">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_password" class="layui-input" placeholder="请输入密码">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">电话号码</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_phone" class="layui-input" placeholder="请输入电话">
                </div>
            </div>

            <div class="layui-form-item layui-form-pane">
                <label class="layui-form-label">等级</label>
                <div class="layui-input-inline">
                    <input type="text" id="insert_roleId" class="layui-input" placeholder="请输入等级">
                </div>
            </div>
        </div>
    </script>




</div>

<div class="layui-footer" align="center">
    <!-- 底部固定区域 -->
    copyright@2022-2024   www.dly2024.com  何志超
</div>
</div>
<script src="/layui/layui.js" charset="utf-8"></script>
<script src="/jquery/jquery-3.6.0.js" charset="utf-8"></script>
<script>
    //模糊搜索
    $("#searchVal").click(function () {
        let search_username = $("#search_username").val();
        let search_collage = $("#search_collage").val();
        tableflush(search_username, search_collage);
    });

    $("#iReset").click(function () {
        $("#search_username").val('');
        $("#search_collage").val('');
        tableflush('', '');
    });
    function tableflush(search_username, search_sex,search_birthday,search_grade,search_rank,search_jobDate,
    search_collage, search_password,search_phone,search_roleId) {
        let param = {};
        if (search_username === undefined || search_username === null)
            search_username = '';
        if (search_sex === undefined || search_sex === null)
            search_sex = '';
        if (search_birthday === undefined || search_birthday === null)
            search_birthday = '';
        if (search_grade === undefined || search_grade === null)
            search_grade = '';
        if (search_rank === undefined || search_rank === null)
            search_rank = '';
        if (search_jobDate === undefined || search_jobDate === null)
            search_jobDate = '';
        if (search_collage === undefined || search_collage === null)
            search_collage = '';
        if (search_password === undefined || search_password === null)
            search_password = '';
        if (search_phone === undefined || search_phone === null)
            search_phone = '';
        if (search_roleId === undefined || search_roleId === null)
            search_roleId = '';

        param.username = search_username;              // {YuanGongHao:''}
        param.sex = search_sex;   // {Name:''}
        param.birthday = search_birthday;   // {Name:''}
        param.grade = search_grade;              // {YuanGongHao:''}
        param.rank = search_rank;   // {Name:''}
        param.jobDate = search_jobDate;
        param.collage = search_collage;   // {Name:''}
        param.password = search_password;              // {YuanGongHao:''}
        param.phone = search_phone;   // {Name:''}
        param.roleId = search_roleId;
        //查询

        layui.use('table', function () {
            var table = layui.table;

            table.render({
                elem: '#test',
                url: '/teacher/findByPage',
                where: param,
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                title: '用户数据表',
                cols: [
                    [
                        {type: 'checkbox', fixed: 'left'},
                        {field: 'Id', title: 'ID', width: 80, fixed: 'left', unresize: true, sort: true},
                        {field: 'username', title: '姓名', width: 120, edit: 'text'},
                        {field: 'sex', title: '性别', width: 120, edit: 'text'},
                        {field: 'birthday', title: '生日', width: 120, edit: 'text'},
                        {field: 'grade', title: '成绩', width: 120, edit: 'text'},
                        {field: 'rank', title: '职称', width: 120, edit: 'text'},
                        {field: 'jobDate', title: '工作日期', width: 120, edit: 'text'},
                        {field: 'collage', title: '毕业大学', width: 120, edit: 'text'},
                        {field: 'password', title: '密码', width: 120, edit: 'text'},
                        {field: 'phone', title: '电话号码', width: 120, edit: 'text'},
                        {field: 'roleId', title: '等级', width: 120, edit: 'text'},
                        {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200}
                    ]
                ],
                page: true,
                limits: [10]

            });

            //头工具栏事件
            table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.ID);
                switch (obj.event) {
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：' + data.length + ' 个');
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选' : '未全选');
                        break;
                    case 'insertData':
                        //增加信息
                        layer.open({     // 弹出框处理  模态框
                            type: 1               // 模态框
                            , title: '新增员工' //不显示标题栏
                            , closeBtn: false
                            , area: ['500px', '500px']  // 宽和高
                            , shade: 0.5
                            , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                            , btn: ['新增', '取消']
                            , btnAlign: 'c'
                            , moveType: 1 //拖拽模式，0或者1
                            , content: $('#insert_form').html()         // 引入自定义表单
                            , btn1: function (index, layero) {            // 这个是新增按钮点击事件
                                // layer.msg("新增按钮执行");
                                let username = $("#insert_username").val();
                                let sex = $("#insert_sex").val();
                                let birthday = $("#insert_birthday").val();
                                let grade = $("#insert_grade").val();
                                let rank = $("#insert_rank").val();
                                let jobDate = $("#insert_jobDate").val();
                                let collage = $("#insert_collage").val();
                                let password = $("#insert_password").val();
                                let phone = $("#insert_phone").val();
                                let roleId = $("#insert_roleId").val();

                                $.ajax({
                                    url: "/teacher_info/insert",           // 请求路径
                                    type: "post",                  // 请求的方式，不区分大小写
                                    cache: false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                                    contentType: "application/json;charset=utf-8",
                                    data: JSON.stringify({
                                        username: username,
                                        sex:sex,
                                        birthday: birthday,
                                        grade: grade,
                                        rank: rank,
                                        jobDate: jobDate,
                                        collage: collage,
                                        password: password,
                                        phone: phone,
                                        roleId: roleId
                                    }),
                                    datatype: "json",        // 返回类型，text文本、html页面、json数据
                                    success: function (response) {
                                        console.log("返回: " + response);
                                        if (response.code === 200) {
                                            layer.msg("新增用户成功!");
                                            layer.close(index);                         // 关闭当前窗口
                                            tableFlush();
                                        }
                                    },
                                    error: function (response) {
                                        console.log("出错返回: " + response);
                                    }
                                });
                            }
                            , success: function (layero) {
                                // 这里是为了弹出窗口初始化数据的
                                // $("#insert_username").val("这是一个测试用户名");
                            }
                        });
                        break;

                    //自定义头工具栏右侧图标 - 提示
                    case 'LAYTABLE_TIPS':
                        layer.alert('这是工具栏右侧自定义的一个图标按钮');
                        break;
                }
                ;
            });

            //删除信息
            table.on('tool(test)', function (obj) {
                var data = obj.data;
                //console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {

                        $.ajax({
                            url: "/teacher_info/delete",           // 请求路径
                            type: "post",                  // 请求的方式，不区分大小写
                            cache: false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                            data: ({
                                Id: data.Id
                            }),
                            datatype: "json",        // 返回类型，text文本、html页面、json数据
                            success: function (response) {
                                console.log("返回: " + response);
                                if (response.code === 200) {
                                    layer.msg("删除用户成功!");
                                    layer.close(index);                         // 关闭当前窗口
                                    tableflush();
                                }
                            },
                            error: function (response) {
                                console.log("出错返回: " + response);
                            }
                        });
                        layer.close(index);
                    });
                }

                else if (obj.event === 'edit') {
                    layer.open({     // 弹出框处理  模态框
                        type: 1               // 模态框
                        , title: '修改老师信息' //不显示标题栏
                        , closeBtn: false
                        , area: ['500px', '500px']  // 宽和高
                        , shade: 0.5
                        , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                        , btn: ['保存', '取消']
                        , btnAlign: 'c'
                        , moveType: 1 //拖拽模式，0或者1
                        , content: $('#insert_form').html()         // 引入自定义表单
                        , btn1: function (index, layero) {            // 这个是新增按钮点击事件
                            // layer.msg("新增按钮执行");
                            let username = $("#insert_username").val();
                            let sex = $("#insert_sex").val();
                            let birthday = $("#insert_birthday").val();
                            let grade = $("#insert_grade").val();
                            let rank = $("#insert_rank").val();
                            let jobDate = $("#insert_jobDate").val();
                            let collage = $("#insert_collage").val();
                            let password = $("#insert_password").val();
                            let phone = $("#insert_phone").val();
                            let roleId = $("#insert_roleId").val();
                            $.ajax({
                                url: "/teacher_info/update",           // 请求路径
                                type: "post",                  // 请求的方式，不区分大小写
                                cache: false,                  // 关闭缓存，目的是为了避免部分浏览器缓存加载出错(IE)
                                contentType: "application/json;charset=utf-8",
                                data: JSON.stringify({
                                    Id:data.Id,
                                    username: username,
                                    sex:sex,
                                    birthday: birthday,
                                    grade: grade,
                                    rank: rank,
                                    jobDate: jobDate,
                                    collage: collage,
                                    password: password,
                                    phone: phone,
                                    roleId: roleId
                                }),
                                datatype: "json",        // 返回类型，text文本、html页面、json数据
                                success: function (response) {
                                    console.log("返回: " + response);
                                    if (response.code === 200) {
                                        layer.msg("新增用户成功!");
                                        layer.close(index);                         // 关闭当前窗口
                                        tableFlush();
                                    }
                                },
                                error: function (response) {
                                    console.log("出错返回: " + response);
                                }
                            });
                        }
                        , success: function (layero) {
                            // 这里是为了弹出窗口初始化数据的
                            // $("#insert_username").val("这是一个测试用户名");
                            console.log(data);
                            $("#insert_username").val(data.username);
                            $("#insert_sex").val(data.sex);
                            $("#insert_birthday").val(data.birthday);
                            $("#insert_grade").val(data.grade);
                            $("#insert_rank").val(data.rank);
                            $("#insert_jobDate").val(data.jobDate);
                            $("#insert_collage").val(data.collage);
                            $("#insert_password").val(data.password);
                            $("#insert_phone").val(data.phone);
                            $("#insert_roleId").val(data.roleId);
                        }
                    });
                } else if (obj.event === 'new') {
                    layer.msg('自定义按钮触发 data=' + JSON.stringify(data));
                }
            });
        });
    }
    tableflush()

</script>

</body>
</html>